<?php
namespace app\index\controller;

use think\Controller;
use think\Session;

class Index extends Controller
{
    public function index()
    {
        $user = session('user');
        if(!$user){
            $usercont=0;
        }else{
            $usercont=$user;
        }

        $this->assign('usercont',$usercont);
        return $this->fetch('index/main');
    }

    /**
     * 登陆页面
     * @time: 2018-11-13
     */
    public function login(){
        return $this->fetch('index/login');
    }

    /**
     * 注册页面
     * @time: 2018-11-13
     */
    public function register($mobile=null){
        $this->assign('mobile',$mobile);
        return $this->fetch();
    }

    /**
     * 登陆验证
     * @time: 2018-11-13
     */
    public function loginCheck(){
        $userName = input('post.username');
        $userPass = input('post.password');
        $code=input('post.captcha');

        if(!captcha_check($code)){
            //验证失败
            return "验证码错误！";
        }else{
            $password=md5($userPass);
            $has = db('user')
                ->where('u_email', $userName)
                ->where('u_pass', $password)
                ->find();
            if(empty($has)){
                return "用户名或密码错误！";
            }
            session('user',input('post.username'));
            return 200;
        }


    }

    /**
     * 登出
     * @time 2018-11-19
     */
    public function loginout(){
        Session::delete('user');
        $this->redirect('/');
    }

    /**
     * 注册验证
     * @time 2018-11-14
     */
    public function registerCheck(){
        $param = input('post.');

        if(empty($param['companyName'])){
            return "公司名不能为空！";
        }

        if(empty($param['registerNumber'])){

            return "增值税号码不能为空！";
        }

        if(empty($param['fullName'])){

            return "全名不能为空！";
        }

        if(empty($param['email'])){

            return "电子邮件不能为空！";
        }

        if(empty($param['password'])){

            return "密码不能为空！";
        }

        if($param['password']!=$param['Password_second']){
            return "两次密码输入不一致！";
        }
        $password=md5($param['password']);
        $data = [
            'u_company' => $param['companyName'],
            'u_zzshm' => $param['registerNumber'],
            'u_quanming' => $param['fullName'],
            'u_email' => $param['email'],
            'u_pass' => $password
        ];
        db('user')->insert($data);

        return 200;


    }

    /**
     * 个人资料
     */
    public function myinfo(){
        return $this->fetch('index/gerenxinxi');
    }

    /**
     * 大纲仪表页面
     */
    public function ybkj(){
        return $this->fetch('index/yibiao');
    }

    /**
     * 所有产品
     */
    public function allpro(){
        return $this->fetch('index/nidechanpin');
    }

    /**
     * 提现
     */
    public function cash(){
        return $this->fetch('index/tixian');
    }

    /**
     * 提现列表
     */
    public function cash_list(){
        return $this->fetch('index/history');
    }

    /**
     * 组织结构
     */
    public function zuzhi(){
        return $this->fetch('index/zuzhijiegou');
    }

    /**
     * 购买计划
     */
    public function buyplan(){
        return $this->fetch('index/goumaijihua');
    }

    /**
     * 直推伙伴
     */
    public function zhitui(){
        return $this->fetch('index/zhitui');
    }

    /**
     * 购买矩形
     */
    public function buyjz(){
        return $this->fetch('index/matrix');
    }

    /**
     * 用户转移
     */
    public function userzy(){
        return $this->fetch('index/yonghuzhuanyi');
    }


}
